package com.andova.image

import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.andova.glcamera.GlCameraViewActivity
import com.andova.glcamera.GlFrameHThread
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class GlCameraActivityTest {
    @Test
    fun testPageSkip() {
        ActivityScenario.launch(GlCameraViewActivity::class.java)
        GlobalScope.launch {
            var c = 0
            while (true) {
                delay(3000L)
                Espresso.onView(ViewMatchers.isRoot()).perform(ViewActions.swipeUp())
                delay(3000L)
                Espresso.pressBack()
                delay(3000L)
                println("test page skip count:${++c}")
            }
        }
        while (true) {
            Thread.sleep(1000L)
        }
    }

    @Test
    fun testMemGlFrameHT() {
        Thread {
            while (true) {
                GlFrameHThread.get().tryStart()
                Thread.sleep(200L)
                GlFrameHThread.get().tryQuit()
                Thread.sleep(200L)
            }
        }.start()
        Thread {
            while (true) {
                GlFrameHThread.get().tryStart()
                Thread.sleep(200L)
                GlFrameHThread.get().tryQuit()
                Thread.sleep(200L)
            }
        }.start()
        while (true) {
            Thread.sleep(1000L)
        }
    }
}